import { useEffect, useState } from 'react'
import { SolutionHeaderItem,SolutionItem, fetchSolutionAPI } from '@/apis/home'
// import { log } from 'console'

function useSolution() {
  const [headers, setHeaders] = useState<SolutionHeaderItem["caption"]>()
  const [items, setItem] = useState<SolutionItem[]>([])
  useEffect(() => {
    const getSolution = async () => {
      try {
        const res = await fetchSolutionAPI()
        console.log(res);
        setHeaders(res.data.head[0].caption)
        setItem(res.data.data)
      } catch (error) {
        throw new Error('fetch Solution error')
      }
    }
    getSolution()
  }, [])
  // 暴露数据channels
  return {
    headers,items
  }
}

export { useSolution }
